package com.example.glutil;

import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;

import com.example.renderer.ScreenRenderer;
import com.example.state.AppState;

import org.jbox2d.common.Vec2;

/**
 * Created by Lucas on 08/07/13.
 */
public class WorldCoord {

    private static final String TAG = "WorldCoord";

    public static Vec2 getCoordinates(Context context, Vec2 touch){
        Vec2 worldCoordinates = new Vec2();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int widthDevice = size.x;
        int heightDevice = size.y;

        float widthSimulation = 2f;
        float heightSimulation = 2f* AppState.RATIOHEIGHT;
        float yOffset = ScreenRenderer.YOFFSET;
        worldCoordinates.x = (widthSimulation*touch.x)/widthDevice+yOffset;
        worldCoordinates.y = ((heightSimulation*touch.y)/heightDevice);
        //Log.d(TAG, "\n World coordinates: "+worldCoordinates.x+","+worldCoordinates.y);
        return worldCoordinates;
    }
}
